// Agent scout in project MAPC

/* Initial beliefs and rules */
{ include("rules.asl") } 

!move.

		
+!get_new_target
	: not pos(_,_,_)
	<- .wait("+pos(_,_,_)");		
		!get_new_target.
	
// let the leader delegate a target to the agent	
+!get_new_target
	:	pos(X,Y,Step)
			<- .send(agent3, achieve, delegate_target(X,Y,Step)).
					
// doesn't have a target
+pos(_,_,_) : not target_pos(_,_) 
	<- 	!get_new_target.
			
+!move 	: 	not target_pos(_,_)
		<- .wait("+target_pos(_,_)");
			!move.		


// doesn't have a position
+!move 	: 	not pos(_,_,_)
		<- .wait("+pos(_,_,_)");
			!move.		

// is at desired target	   	 
+!move 	: 	pos(X,Y,_) 
		& 	target_pos(X,Y) 
		<- 	-target_pos(_,_);  
			do(skip);			
			!get_new_target; !!move.			
				
// move towards target
+!move : pos(X,Y,_) & target_pos(DX,DY)
	   <-   jia.astar(X,Y,DX,DY,A,true); do(A); -+last_dir(A);	   
	   		!get_new_target;
			!!move. // continue moving
	   			